package cn.hill4j.tool.spring.std.ds.user.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.hill4j.tool.spring.std.ds.user.entity.User;
import cn.hill4j.tool.spring.std.ds.user.mapper.UserMapper;
import cn.hill4j.tool.spring.std.ds.user.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * TODO Description
 *
 * @author: hillchen
 * Date: 2022-08-08 16:04
 */
@DS("ds1")
@Service
public class UserService   extends ServiceImpl<UserMapper, User> implements IUserService {
    @Override
    @Transactional
    public void saveByName(String name) {
        User user = new User();
        user.setName(name);
        save(user);
    }

    @Override
    public User findByName(String name) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getName,name)
                .last(" limit 1");
        return getOne(queryWrapper);
    }
}
